package com.example.literj.kt.internal.disposables

import com.example.literj.kt.core.Observer
import com.example.literj.kt.internal.operators.QueueDisposable
import java.lang.UnsupportedOperationException

enum class EmptyDisposable : QueueDisposable<Any?> {
    INSTANCE, NEVER;

    override fun dispose() {}

    override fun isDisposed() = this == INSTANCE

    override fun offer(value: Any?): Boolean {
        throw UnsupportedOperationException("Should not be called!")
    }

    override fun offer(v1: Any?, v2: Any?): Boolean {
        throw UnsupportedOperationException("Should not be called!")
    }

    override fun poll(): Nothing? = null

    override fun isEmpty() = true

    override fun clear() {}

    override fun requestFusion(mode: Int) = mode and ASYNC

    companion object {
        fun complete(observer: Observer<*>) {
            observer.onSubscribe(INSTANCE)
            observer.onComplete()
        }

        // TODO finish
/*        fun complete(observer: MaybeObserver<*>) {
            observer.onSubscribe(INSTANCE)
            observer.onComplete()
        }*/

        fun error(e: Throwable?, observer: Observer<*>) {
            observer.onSubscribe(INSTANCE)
            observer.onError(e!!)
        }

/*        fun complete(observer: CompletableObserver) {
            observer.onSubscribe(INSTANCE)
            observer.onComplete()
        }

        fun error(e: Throwable?, observer: CompletableObserver) {
            observer.onSubscribe(INSTANCE)
            observer.onError(e)
        }

        fun error(e: Throwable?, observer: SingleObserver<*>) {
            observer.onSubscribe(INSTANCE)
            observer.onError(e)
        }

        fun error(e: Throwable?, observer: MaybeObserver<*>) {
            observer.onSubscribe(INSTANCE)
            observer.onError(e)
        }*/
    }
}